package com.mgr.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mgr.dao.TransactionDao;
import com.mgr.model.Transactions;
import com.mgr.service.AccountService;
import com.mgr.service.TransactionService;

@Service
public class TransactionServiceImpl implements TransactionService {

	@Autowired
	private TransactionDao transDao;
	@Autowired
	private AccountService accountService;

	@Transactional
	public void addtransaction(Transactions transaction) {
		transDao.addtransaction(transaction);
	}


	@Transactional
	public List<Transactions> getTransByTime(int accId, Date startDate,
			Date endDate) {
		// TODO Auto-generated method stub
		return transDao.getTransByTime(accId, startDate, endDate);
	}

	@Transactional
	public void transaction(int accId1, int accId2, int amount, int transType) {
		Transactions transaction=new Transactions();
		transaction.setAccId1(accId1);
		transaction.setAccId1(accId2);
		transaction.setAmount(amount);
		transaction.setTransDate(new Date());
		
		accountService.updateBalance(accId1, -amount);
		accountService.updateBalance(accId2, amount);
	}


}
